<!DOCTYPE html>
<html lang="en">

<head>
    <#include "/jh/admin/components/meta.html" />
    <title>签到学生 ${metaTitleSuffix!}</title>
    <#include "/jh/admin/components/stylesheets.html" />
    <style type="text/css">
    .el-select .el-input {
        width: 130px;
    }

    .input-with-select .el-input-group__prepend {
        background-color: #fff;
    }
    </style>
</head>

<body>
    <div id="app">
        <el-container>
            <#assign menuIndex="1-4" />
            <#include "/jh/admin/components/menu.html" />
            <el-container>
                <#include "/jh/admin/components/header.html" />
                <el-main>
                    <template>
                        <el-row>
                            <el-col :span="12">
                                <div class="title theme-color1">签到学生</div>
                            </el-col>
                        </el-row>
                        <el-date-picker v-model="date" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" @change="onDateChange" unlink-panels="true">
                        </el-date-picker>
                        <el-select v-model="schoolId" placeholder="校区" clearable @change='onSchoolChanged'>
                            <el-option v-for="item in schools" :key="item.id" :label="item.name" :value="item.id">
                            </el-option>
                        </el-select>
                        <el-select v-model="staffId" placeholder="老师" clearable @change='onStaffChanged'>
                            <el-option v-for="item in staffs" :key="item.id" :label="item.englishName" :value="item.id">
                                {{item.englishName}} <span style="color: gray">{{item.name}}</span>
                            </el-option>
                        </el-select>
                        <el-select v-model="courseId" placeholder="课程" clearable @change='onCourseChanged'>
                            <el-option v-for="item in courses" :key="item.id" :label="item.name" :value="item.id">
                            </el-option>
                        </el-select>
                        <el-select v-model="tag" placeholder="级别" clearable @change='onTagChanged'>
                            <el-option v-for="item in tags" :key="item" :label="item" :value="item">
                            </el-option>
                        </el-select>
                        <a href="/jh/admin/arrange/downloadStudents?startTime=${startTime!}&${endTime!}&schoolId=${schoolId!''}&staffId=${staffId!''}&courseId=${courseId!''}&tag=${tag!''}" target="_blank"><i class="el-icon-download"></i>导出excel</a>
                        <!-- <el-col :span='12'>
                            <el-input placeholder="学生姓名/电话,如:刘同学" v-model="keyword" class="input-with-select" clearable>
                                <el-select v-model="selectedSchool" slot="prepend" placeholder="校区" clearable>
                                    <el-option :label="item.name" :value="item.id" v-for='item in schools'></el-option>
                                </el-select>
                                <el-button slot="append" icon="el-icon-search" @click='onSearch'></el-button>
                            </el-input>
                        </el-col> -->
                        <el-table ref="multipleTable" :data="list" tooltip-effect="dark" :stripe='true' style="width: 100%" v-loading="loadingData" id='dataTable'>
                            <el-table-column prop="startTime" label="日期" width="200">
                            </el-table-column>
                            <el-table-column prop="name" label="课程" width="200">
                            </el-table-column>
                            <el-table-column prop="topic" label="主题" width="400">
                            </el-table-column>
                            <el-table-column prop="studentName" label="学生">
                            </el-table-column>
                            <el-table-column prop="mobile" label="电话">
                            </el-table-column>
                            <el-table-column prop="schoolName" label="校区">
                            </el-table-column>
                            <!-- <el-table-column fixed="right" label="操作" width="170">
                                <template slot-scope="scope">
                                    <el-button @click="edit(scope.row)" type="text" size="small">编辑</el-button>
                                    <el-button @click="del(scope.row)" type="text" size="small" style="color: red;">删除</el-button>
                                </template>
                            </el-table-column> -->
                        </el-table>
                        <#include "/jh/admin/components/page.html" />
                    </template>
                </el-main>
            </el-container>
        </el-container>
        <#include "/jh/admin/components/footer.html" />
    </div>
    <#include "/jh/admin/components/scripts.html" />
    <script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data() {
            return {
                loadingData: false,
                date: ['${startDate!}', '${endDate!}'],
                list: [],
                schoolId: null,
                staffId: null,
                courseId: null,
                tag: null,
                schools: JSON.parse('${schools!""}'),
                staffs: JSON.parse('${staffs!""}'),
                courses: JSON.parse('${courses!""}'),
                tags: [],
            }
        },
        mounted: function() {
            var str = '${items!}'
            if (str != '') {
                this.list = JSON.parse(str);
            } else {
                alert('加载失败')
            }


            var tagStr = '${tags!}';
            if (tagStr != '') {
                this.tags = tagStr.split(",");
                this.tags.pop();
            }
            var schoolId = '${schoolId!""}'
            if (schoolId != '') {
                this.schoolId = Number(schoolId);
            }
            var staffId = '${staffId!""}'
            if (staffId != '') {
                this.staffId = Number(staffId);
            }
            var courseId = '${courseId!""}'
            if (courseId != '') {
                this.courseId = Number(courseId);
            }
            var tag = '${tag!""}'
            if (tag != '') {
                this.tag = tag;
            }
        },
        methods: {
            onSearch() {
                var _self = this;
                // this.loadingData = true;
                var keys = [
                    { value: this.keyword, key: 'keyword' },
                    { value: this.selectedSchool, key: 'schoolId' }
                ]
                goPage(1, keys)
                // setMsg();
                return
                var loading = this.$loading({
                    lock: true,
                    text: '加载中',
                    // spinner: 'el-icon-loading',
                    target: '#dataTable',
                    // background: 'rgba(0, 0, 0, 0.7)'
                });
            },
            onSchoolChanged() {
                var keys = [
                    { key: 'schoolId', value: this.schoolId }
                ]
                goPage(1, keys)
            },
            onStaffChanged() {
                var keys = [
                    { key: 'staffId', value: this.staffId }
                ]
                goPage(1, keys)
            },
            onCourseChanged() {
                var keys = [
                    { key: 'courseId', value: this.courseId }
                ]
                goPage(1, keys)
            },
            onTagChanged() {
                var keys = [
                    { key: 'tag', value: this.tag }
                ]
                goPage(1, keys)
            },
            add() {
                window.location.href = "/jh/admin/studentFollow/info?studentId=${(info.id)!}";
            },
            edit(item) {
                window.location.href = "/jh/admin/studentFollow/info?followId=" + item.id;
            },
            del(item) {
                var self = this;
                confirm("确认删除？请谨慎操作", "确认", function() {
                    var param = Qs.stringify({
                        followId: item.id
                    });
                    axios({
                            url: '/jh/admin/studentFollow/delete',
                            method: 'post',
                            data: param,
                            headers: {
                                'Content-Type': 'application/x-www-form-urlencoded'
                            }
                        })
                        .then(function(response) {
                            if (response.data.status == 200) {
                                endLoading();
                                window.location.href = "/jh/admin/studentFollow?studentId=${(info.id)!}";
                                // msg("登录成功");
                            } else {
                                endLoading();
                                msg(response.data.msg);
                                console.log(response.data);
                            }
                        })
                        .catch(function(error) {
                            endLoading();
                            msg("删除失败");
                            console.log(error);
                        });
                })
            },
            onDateChange(val) {
                var keys = [
                    { key: 'startDate', value: val[0] },
                    { key: 'endDate', value: val[1] }
                ]
                goPage(1, keys)
                // window.location.href = "/jh/admin/arrange/list?startDate=" + val[0] + "&endDate=" + val[1];
            },
            onStaffChanged() {
                var keys = [
                    { key: 'staffId', value: this.staffId }
                ]
                goPage(1, keys)
            },
            onPageChange(val) {
                // console.log('当前页: {val}' + val);
                goPage(val)
            }
        }
    })
    </script>
    <script type="text/javascript">
    const h = vue.$createElement;

    function setMsg() {

    }
    </script>
    <style type="text/css">
    .title {
        font-size: 18px;
        font-weight: bold;
    }

    .operations {
        text-align: right;
    }
    </style>
    <#include "/jh/admin/components/msg.html" />
</body>

</html>